package com.demo.zhlg.controller;

import com.demo.zhlg.mapper.TasksMapper;
import com.demo.zhlg.util.Result;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.demo.zhlg.entity.Tasks;
import com.demo.zhlg.service.TasksService;
import org.sqlite.date.DateFormatUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import static com.demo.zhlg.entity.table.TasksTableDef.TASKS;

/**
 *  控制层。
 *
 * @author lenovo
 * @since 2025-04-26
 */
@RestController
@RequestMapping("/tasks")
public class TasksController {

    @Autowired
    private TasksService tasksService;

    @GetMapping("getTaskList")
    public Object getTaskList(){
        return tasksService.getTaskList();
    }

    @GetMapping("increaseViewCount")
    public Object increaseViewCount(@RequestParam Integer taskId){
        return tasksService.increaseViewCount(taskId);
    }

    @PostMapping("applyTask")
    public Object applyTask(@RequestParam Integer taskId){
        return tasksService.applyTask(taskId);
    }

    @GetMapping("getTaskDetail")
    public Object getTaskDetail(@RequestParam Integer taskId){
        return Result.success(tasksService.getById(taskId));
    }

    @GetMapping("getSimilarTasks")
    public Object getSimilarTasks(@RequestParam Integer taskId){
        return tasksService.getSimilarTasks(taskId);
    }

    @GetMapping("searchTasks")
    public Object searchTasks(@RequestParam String keyword){
        return tasksService.searchTasks(keyword);
    }

    @PostMapping("publishTask")
    public Object publishTask(@RequestBody Tasks task) {
        return tasksService.publishTask(task);
    }

    @GetMapping("getMyPublishedTasks")
    public Object getMyPublishedTasks() {
        return tasksService.getMyPublishedTasks();
    }

    @GetMapping("getMyAppliedTasks")
    public Object getMyAppliedTasks(){
        return tasksService.getMyAppliedTasks();
    }

    @PostMapping("cancelApply")
    public Object cancelApply(@RequestParam Integer taskId){
        return tasksService.cancelApply(taskId);
    }

    @PostMapping("cancelTask")
    public Object cancelTask(@RequestParam Integer taskId){
        return tasksService.cancelTask(taskId);
    }

    @GetMapping("generateOrder")
    public Object generateOrder(@RequestParam Integer taskId){
        return tasksService.generateOrder(taskId);
    }

    @GetMapping("isPublisher")
    public Object isPublisher(@RequestParam Integer taskId){
        return tasksService.isPublisher(taskId);
    }

    @GetMapping("isAlreadyApplied")
    public Object isAlreadyApplied(@RequestParam Integer taskId){
        return tasksService.isAlreadyApplied(taskId);
    }

    @GetMapping("getTaskByCategory")
    public Object getTaskByCategory(@RequestParam Integer categoryId){
        return tasksService.getTaskByCategory(categoryId);
    }

    @GetMapping("updateTaskExpiration")
    public Object updateTaskExpiration(){
        return tasksService.updateTaskExpiration();
    }
}
